<template>
  <div>
    <el-dialog 
       :visible.sync="visible" 
       :title="title"
       :close-on-click-modal="false"
        append-to-body
        top="10vh"
        :close-on-press-escape="false"
       >
        <el-form :model="form">
          <el-form-item label="标签名">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="排序">
            <el-input v-model="form.sorts"></el-input>
          </el-form-item>
          <el-form-item label="简拼">
            <el-input v-model="form.number"></el-input>
          </el-form-item>
          <el-form-item label="标签编码">
            <el-input v-model="form.code"></el-input>
          </el-form-item>
          <el-form-item label="删除状态">
            <el-input v-model="form.start"></el-input>
          </el-form-item>
          <el-form-item label="标签类型">
            <el-input v-model="form.type"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="save()">确 定</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:{
    title:{
        type:String,
        required:true,
    },
    itemData:{
      type:Array,
      required:true,
    },
  },
data(){
    return {
        form: {
            sorts: "",
            name: "",
            number: "",
            code:"",
            start:"",
            type:"",
        },
        visible:false,
    }
  },
  methods:{
    save(){
      if(this.title === "新增"){
        let data = {
          sorts:this.form.sorts,
          name:this.form.name,
          number:this.form.number,
          type:this.form.type,
          code:this.form.code,
          definition:this.form.definition,
        }
        this.itemData.push(data);
        sessionStorage.setItem('tdata', JSON.stringify(this.itemData)) 
        this.visible = false
        this.visible = false

      }else if(this.title === "修改"){
        this.visible = false
      }
    },
    async initAdd() {
      this.visible = true
    },
  }
}
</script>

<style>

</style>